<?php

/**
 * Auto Code generation
 *
 * @version $Rev:$
 * @license
 */
class Admin_Model_Roles extends Zend_Db_Table_Abstract
{

    public function __construct($config = array())
    {
        $this->_db = Zend_Db_Table::getDefaultAdapter();
        parent::__construct($config);
    }
    public function insert($arr){
        $table = new System_Table_Roles();
        $table->insert($arr);
    }
    public function update($code,$arr){
        if($code != ''){
            $table = new System_Table_Roles();
            $where = $table->getAdapter()->quoteInto('CODE = ?', $code);
            $table->update($arr,$where);
            
            $tableUser = new System_Table_Users();
            $whereUser = $tableUser->getAdapter()->quoteInto('ROLE = ?', $code);
            $tableUser->update(array('ROLE'=>$arr['CODE']),$whereUser);        
        }
    }
    public function delete($arr){
        if(count($arr) > 0){
            $table = new System_Table_Roles();
            foreach($arr as $code){
                if($code != ""){
                    config::removeRoles($code);
                    $where = $table->getAdapter()->quoteInto('CODE = ?', $code);
                    $table->delete($where);
                }
            }
        }
    }
}

